package erfgame.core.world.terrain.color;

import java.util.Random;


import erfgame.core.Rotation;
import erfgame.core.world.World;

public class RandomVerticalFibreTerrainColorMapFactory 
	implements TerrainColorMapFactory {
	
	private int minColor;
	private int maxColor;
	private int minFibreLength;
	private int maxFibreLength;
	private Random random;
	
	public RandomVerticalFibreTerrainColorMapFactory(
			int minColor, 
			int maxColor, 
			int minFibreLength, 
			int maxFibreLength,
			Random random
	) {
		this.minColor = minColor;
		this.maxColor = maxColor;
		this.minFibreLength = minFibreLength;
		this.maxFibreLength = maxFibreLength;
		this.random = random;
	}

	public int[][][] getColorMap(World world, int width, int height, int depth) {
		int[][][] result = new int[width][height][depth];
		int dFibreLength = maxFibreLength - minFibreLength + 1;
		for( int x=width; x>0; ) {
			x--;
			for( int y=height; y>0; ) {
				y--;
				int z = 0;
				while( z < depth ) {
					int color = SampledTerrainColorSource.getRandomColor(minColor, maxColor, random);
					int fibreLength = minFibreLength + Math.abs(random.nextInt()) % dFibreLength;
					for( int i=0; i<fibreLength; i++ ) {
						int lz = (i + z)%depth;
						result[x][y][lz] = color;
					}
					z += fibreLength;
				}
			}
		}
		return MappedTerrainColorSource.getRandomColorMap(
				minColor, 
				maxColor, 
				random, 
				width, 
				height, 
				depth
		);
	}

}
